package com.baiku.sanhos.config;

import com.baiku.sanhos.utils.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;





@Configuration
@Slf4j
public class WebConfig implements WebMvcConfigurer {


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        log.info( FileUtil.UPLOADS_PATH);
        //当遇到/uploads/**时重定向到磁盘里面找资源
        registry.addResourceHandler("/uploads/**")
                .addResourceLocations("file:///" + FileUtil.UPLOADS_PATH);


    }
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        log.debug("加载了旧的拦截器");
        registry.addMapping("/**")
                .allowedHeaders("*")
                .allowedMethods("*")
                .allowedOriginPatterns("*") // .allowedOrigins("*")
                .allowCredentials(true)
                .maxAge(3600);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new XFrameOptionsInterceptor());
    }

}
